const http = require('http')

const path = require('path')

const fs = require('fs')

const serve = http.createServer()

serve.on('request',(req,res)=>{
    const url = req.url

    // const fpath = path.join(__dirname,url)
    
    let fpath = ''
    if(url === '/'){
        fpath = path.join(__dirname,'./clock/change.html')
    }else{
        fpath = path.join(__dirname,'/clock',url)
    }


    console.log(fpath);
    fs.readFile(fpath,'utf8',(err,dataStr)=> {
        if(err){
            return res.end('404 not found')
        }
            res.end(dataStr)
    })
})

serve.listen(80,()=>{
    console.log('server running at http://127.0.0.1');
})